package com.naiterui.ehp.bs.esign.repository.mysql;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.naiterui.common.repository.core.BaseJpaRepository;
import com.naiterui.ehp.bs.esign.entity.mysql.EsignDoctor;

/**
 * @author guoyongxiang
 * @date 2019/12/2 10:54
 * @since 1.0.0
 */
@Repository
public interface IEsignRecomEsignDoctorRepository extends BaseJpaRepository<EsignDoctor, Long> {

    /**
     * 根据医生ID查询签名医生信息
     *
     * @param doctorId
     *
     * @return
     */
    EsignDoctor findFirstByDoctorId(Long doctorId);

    /**
     * 根据身份证号查询签名医生
     * @param idcard
     * @return
     */
    EsignDoctor findFirstByIdCard(String idcard);

    /**
     * 根据签名平台用户ID查询签名用户信息
     *
     * @param openId
     *
     * @return
     */
    EsignDoctor findFirstByOpenId(String openId);


    /**
     * 根据手机号查询签名信息
     *
     * @param phone
     *
     * @return
     */
    EsignDoctor findFirstByPhone(String phone);

    /**
     * 根据身份证号和doctorId查询
     * @param doctorId
     * @param idCard
     * @return
     */
    EsignDoctor findFirstByDoctorIdAndIdCard(Long doctorId, String idCard);

    EsignDoctor findFirstByIdCardAndAuthStatus(String idCard, Integer authStatus);

    /**
     * 修改免密状态
     * 
     * @param noSecret
     * @param authPwd
     * @param id
     */
    @Modifying
    @Query(value = "update recom_esign_doctor set no_secret = ?1, auth_pwd = ?2 where id = ?3", nativeQuery = true)
    void updateNoSecretAuthPwd(Integer noSecret, String authPwd, Long id);
}
